//
//  SlideBarItemButton.m
//  WEIMO
//
//  Created by Lixiaoyong on 13-6-13.
//  Copyright (c) 2013年 广州从兴电子开发有限公司. All rights reserved.
//

#import "SlideBarItemButton.h"

@implementation SlideBarItemButton
@synthesize middleImage,itemName;
@synthesize item;

- (void)dealloc
{
    self.middleImage = nil;
    self.itemName = nil;
    self.item = nil;
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGRect rect = CGRectZero;
        self.middleImage = [[[UIImageView alloc] initWithFrame:rect] autorelease];
        self.middleImage.backgroundColor = [UIColor clearColor];
        [self addSubview:self.middleImage];
        
        self.itemName = [[[UILabel alloc] initWithFrame:rect] autorelease];
        self.itemName.backgroundColor = [UIColor clearColor];
        self.itemName.textColor = [UIColor grayColor];
        self.itemName.textAlignment = NSTextAlignmentCenter;
        self.itemName.font = [UIFont fontWithName:@"CourierNewPS-BoldMT" size:16.0];
        [self addSubview:self.itemName];
    }
    return self;
}

#pragma mark - protected methods

//设置frame
- (void)refreshSelfFrame:(CGRect)frame
{
    float oX = frame.size.width / 2;
    float oY = frame.size.height / 2;
    CGRect rect = CGRectMake(oX - 22, oY - 32, 43, 43);
    self.middleImage.frame = rect;
    
    rect.origin.y = rect.origin.y + rect.size.height;
    rect = CGRectMake(0, rect.origin.y, frame.size.width, frame.size.height-rect.origin.y);
    self.itemName.frame = rect;
}

//flag:YES-选中状态   NO-normal状态
- (void)refreshButtonState:(BOOL)flag
{
    UIColor *color = [UIColor clearColor];
    if (flag)
    {
        [self setBackgroundImage:[UIImage imageNamed:@"cebianlan_click@2x.png"] forState:UIControlStateNormal];
        color = [UIColor whiteColor];
        self.middleImage.image = [UIImage imageNamed:self.item.others];
    }
    else
    {
        [self setBackgroundImage:[UIImage imageNamed:@"cebianlan@2x.png"] forState:UIControlStateNormal];
        color = [UIColor grayColor];
        self.middleImage.image = [UIImage imageNamed:self.item.valueDispName];
    }
    self.itemName.textColor = color;
}

@end